/*
 * TestDumpCppRepTokenList.c
 *
 *  Created on: 2012/05/31
 *      Author: guanxiaoying
 */
#include "TestDump.h"
static VOID dumpRepListToken( AST astRep ){
	sprintf( tempBuf, header_format, dumpGetStr(XML_RECORD), astRep );
	dumpOutputStream( tempBuf );

	if( CRepListToken.isParameter( astRep ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_VALUE), "parameter-index");
		dumpOutputStream( tempBuf );
		sprintf( constantBuffer, "%d", CRepListToken.getParamIndex( astRep ) );
		dumpParameterStr( constantBuffer );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_VALUE)  );
		dumpOutputStream( tempBuf );
	}else{
		AST astCode = CRepListToken.getCodeScp( astRep );
		dumpCodeScopeAsField(astCode);

		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_NAME), "");
		dumpOutputStream( tempBuf );
		dumpParameterStr( CRepListToken.getTokenLabel( astRep ) );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_NAME)  );
		dumpOutputStream( tempBuf );

	}
	sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_FLAG), "before-##");
	dumpOutputStream( tempBuf );
	dumpParameterStr( CRepListToken.isBeforeSharpSharp( astRep )?"true":"false" );
	sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_FLAG)  );
	dumpOutputStream( tempBuf );

	sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_FLAG), "after-##");
	dumpOutputStream( tempBuf );
	dumpParameterStr( CRepListToken.isAfterSharpSharp( astRep )?"true":"false" );
	sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_FLAG)  );
	dumpOutputStream( tempBuf );

	sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_FLAG), "after-#");
	dumpOutputStream( tempBuf );
	dumpParameterStr( CRepListToken.isAfterSharp( astRep )?"true":"false" );
	sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_FLAG)  );
	dumpOutputStream( tempBuf );

	sprintf( tempBuf, tail_format, dumpGetStr(XML_RECORD) );
	dumpOutputStream( tempBuf );
}
VOID DumpRepListToken( PSZ szPath, PSZ postfix ){
	AST astRep;
	AST astMax = CPPOutput.CRepListToken->getMax();
	if( szPath == NULL ){
		return;
	}
	strcpy( file_buf, szPath );
	file_buf[strlen(szPath)] = '\0';
	strcat(file_buf, postfix );
	file_buf[strlen(szPath)+strlen(postfix)] = '\0';
	if( COEXIT_SUCCESS == dumpOutputStreamInit_file(file_buf)){
		sprintf( tempBuf, top_header, dumpGetStr(XML_REPLSTTKN) );
		dumpOutputStream( tempBuf );
		for( astRep = MIN_ARRAY; astRep <= astMax; astRep++ ){
			dumpRepListToken( astRep );
		}
		sprintf( tempBuf, top_end, dumpGetStr(XML_REPLSTTKN) );
		dumpOutputStream( tempBuf );
		dumpOutputStreamEnd_file();
	}
}

